<?php

namespace App\Controller\Admin;

use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Contract\ResponseInterface;
use Psr\Container\ContainerInterface;

class BaseController
{
    #[Inject]
    protected ContainerInterface $container;

    #[Inject]
    protected RequestInterface $request;

    #[Inject]
    protected ResponseInterface $response;

    //成功响应
    public function success($data = [],$code = 0): \Psr\Http\Message\ResponseInterface
    {
        return $this->response->json(['code'=> $code,'data'=> $data,'msg' => 'success']);
    }

    //错误响应
    public function error($message = '', $code = -1): \Psr\Http\Message\ResponseInterface
    {
        return $this->response->json(['code'=> $code,'msg' => $message]);
    }

    //获取分页参数
    public function getSkipPageSize(): array
    {
        $page = $this->request->input('page',1);
        $pageSize = $this->request->input('pageSize',10);
        $skip = ($page-1) * $pageSize;
        return [$skip,$pageSize];
    }
}